<template>
  <div class="song-list">
    <van-nav-bar title="我喜欢的音乐" left-text="" :flex="false" />
    <div class="jianjie-head">
      <img :src="coverImgUrl" />
      <h4>我喜欢的音乐</h4>
    </div>
    <div class="music-list">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <van-cell v-for="(item, index) in list" :key="item.id">
          <p>{{ index + 1 }}</p>
          <span>{{ item.name }}</span>
          <van-icon class="ic1" name="play" />
          <van-icon class="ic2" name="weapp-nav" />
        </van-cell>
      </van-list>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      id: localStorage.getItem("userId"),
      songListId: localStorage.getItem("userLoveSongList"),
      phoneNumber: localStorage.getItem("phoneNumber"),
      password: localStorage.getItem("password"),
      list: [],
      coverImgUrl: "",
      loading: false,
      finished: false,
    };
  },
  // async created() {
  //   const resMusiclist = await loadProductMusicListAPI();
  //   this.musiclist = resMusiclist.data;
  // },
  created() {
    // 获取用户喜欢歌单的id
    axios
      .get("http://localhost:3000/user/playlist?uid=" + this.id)
      .then((res) => {
        localStorage.setItem("userLoveSongList", res.data.playlist[0].id);
      });
    axios.get("http://localhost:3000/login/refresh").then((res) => {
      console.log(res);
    });
    // 查看登录状态
    axios.get("http://localhost:3000/login/status").then((res) => {
      console.log(res);
    });
    // 获取用户喜欢歌单详情
    axios
      .get("http://localhost:3000/user/playlist?uid=1850903983")
      .then((res) => {
        this.list = res.data.playlist.trackIds;
        this.coverImgUrl = res.data.playlist.coverImgUrl;
        console.log(res);
      });
  },
  methods: {
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        /* if (this.list.length >= 10) {
          this.finished = true;
        } */
      }, 1000);
    },
  },
};
</script>

<style scoped>
html,
body {
  background: #2e3432;
}
.jianjie-head {
  width: 100vw;
  height: 25vh;
  background: #c02425; /* fallback for old browsers */
  background: -webkit-linear-gradient(
    to bottom,
    #f0cb35,
    #c02425
  ); /* Chrome 10-25, Safari 5.1-6 */
  background: linear-gradient(
    to bottom,
    #f0cb35,
    #c02425
  ); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */

  display: flex;
  align-items: center;
  justify-content: space-around;
}
.jianjie-head img {
  width: 30vw;
  height: 30vw;
  border-radius: 50%;
}
.jianjie-head h4 {
  color: #fff;
  position: static;
}
.music-list {
  width: 100vw;
  border-radius: 10px 10px 0 0;
}
.music-list h4 {
  width: 90vw;
  height: 8vh;
  border-bottom: #eee 1px solid;
  margin: 0 auto;
  line-height: 8vh;
}
.music-list .van-cell__title {
  background: #0f0;
  position: relative;
}
.van-cell__value--alone p {
  float: left;
  width: 5vw;
  height: 5vw;
  text-align: center;
  line-height: 5vw;
  margin-right: 4vw;
}
.van-cell__value--alone i {
  color: brown;
}
.ic1 {
  position: absolute;
  right: 8vw;
  color: brown;
}
.ic2 {
  position: absolute;
  right: 0;
  color: brown;
}
</style>
